package sp.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import sp.dao.book.BookDAO;
import sp.pojo.Book;
import sp.pojo.BookImgList;
import sp.service.BookImgListService;
import sp.service.BookService;

@Service("bookService")
public class BookServiceImpl implements BookService{
	
	@Autowired
	private BookDAO bookDao;
	
	@Autowired
	private BookImgListService bookImgListService;

	@Override
	public List<Book> listBook(Integer createBy, String isbn, String bookName, String publish, String author,
			Integer condition, Integer bookStatus,  Integer priceRange, String intervalParam, Integer bookLevel1,
			Integer bookLevel2, Integer bookLevel3) throws Exception {
		return bookDao.listBook(createBy, isbn, bookName, publish, author, condition, bookStatus, priceRange, intervalParam, bookLevel1, bookLevel2, bookLevel3);
	}

	@Override
	public Book getBookInfo(Integer bid, String isbn) throws Exception {
		return bookDao.getBookInfo(bid, isbn);
	}

	@Override
	public boolean saveBook(Book book, BookImgList imgList) throws Exception {
		
		if (bookDao.saveBook(book)) {	
			//补全信息
			imgList.setBid(book.getId());
			imgList.setIsbn(book.getIsbn());
			imgList.setCreateBy(book.getCreateBy());
			imgList.setCreateDate(new Date(System.currentTimeMillis()));

			return bookImgListService .saveBookImgList(imgList);
		}
		return false;
	}

	@Override
	public List<Book> listBookWithSearch(String searchParam) {
		return bookDao.listBookWithSearch(searchParam);
	}



}
